#!/bin/sh

die () { echo $@ ; exit 1; }

. ../../nvm.sh

# Remove the stuff we're clobbering.
[ -e "${NVM_DIR}/v0.9.7" ] && rm -R "${NVM_DIR}/v0.9.7"
[ -e "${NVM_DIR}/v0.9.12" ] && rm -R "${NVM_DIR}/v0.9.12"

# Install from binary
nvm install 0.9.7

# Check
[ -d "${NVM_DIR}/v0.9.7" ] || die "nvm install 0.9.7 didn't install"

nvm use 0.9.7

node --version | grep v0.9.7 > /dev/null || die "nvm use 0.9.7 failed"

npm install -g object-is@0.0.0 || die "npm install -g object-is failed"
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"

nvm ls 0.9 | grep v0.9.7 > /dev/null || die "nvm ls 0.9 didn't show v0.9.7"

nvm install 0.9.12 --reinstall-packages-from=0.9 || die "nvm install 0.9.12 --reinstall-packages-from=0.9 failed"

[ -d "${NVM_DIR}/v0.9.12" ] || die "nvm install 0.9.12 didn't install"

nvm use 0.9
node --version | grep v0.9.12 > /dev/null || die "nvm ls 0.9 didn't use v0.9.12"

npm list --global | grep object-is > /dev/null || die "object-is isn't installed"
